﻿using System;
using System.Collections.Generic;
using ProteinInsightInterface;
using System.Windows.Forms;
using System.Text;
using System.Drawing;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace ProteinInsightPlugin
{
    public class MyPlugin : MarshalByRefObject, IProteinInsightPlugin
    {
        public void Run(IProteinInsight pi)
        {
            try
            {
                //  Example Code: 
                /*
                pi.Open("1NME");
                pi.Property.ShaderQuality = IPropertyScene.IShaderQuality.High;
                pi.Property.GeometryQuality = IPropertyScene.IGeometryQuality.VeryHigh;

                IVP VP1 = pi.AddVP(pi.PDBs[0].GetChains("A"), IProteinInsight.IDisplayStyle.Ribbon);
                IVP VP2 = pi.AddVP(pi.PDBs[0].GetChains("B"), IProteinInsight.IDisplayStyle.BallnStick);

                for (Double degree = 0; degree < 360.0f; degree += 5.0)
                {
                    Double radius = 100.0f;
                    Double xPos = radius * Math.Cos(Math.PI * degree / 180.0);
                    Double zPos = radius * Math.Sin(Math.PI * degree / 180.0);
                    pi.Property.Camera.Position = new Vector3((float)xPos, 0, (float)zPos);

                    pi.Idle(50);
                }
                */

                //
                //    write your plug in code here.
                //
                if (pi.PDBs.Count == 0)
                    pi.Open("1NME");

                //	Set VP1 as ribbon visualization of Chain A
                IVP VP1 = pi.AddVP(pi.PDBs[0].GetChains("A"), IProteinInsight.IDisplayStyle.Ribbon);
                //	Set VP2 as ball&stick visualization of Chain B
                IVP VP2 = pi.AddVP(pi.PDBs[0].GetChains("B"), IProteinInsight.IDisplayStyle.BallnStick);

                //	Change Helix color to red
                VP1.PropertyRibbon.Helix.Color = Color.Red;
                //	Change color scheme to residue color scheme
                VP2.Property.ColorScheme = IProperty.IColorScheme.Residue;

                //	rotate camera in the world space
                for (Double degree = 0; degree < 360.0f; degree += 5.0)
                {
                    Double xPos = 100.0 * Math.Cos(Math.PI * degree / 180.0);
                    Double zPos = 100.0 * Math.Sin(Math.PI * degree / 180.0);
                    pi.Property.Camera.Position = new Vector3((float)xPos, 0, (float)zPos);
                    pi.Idle(10);
                }

                //	Make screen image to "1NME.png"
                pi.SaveImage("1NME.png", 800, 600, IProteinInsight.IImageFormat.PNG);		
            }
            catch (Exception e)
            {
                pi.Utility.OutputMsg(e.ToString());
            }
        }

        public String Name
        {
            get
            {
                return "TutorialRunScriptCode(Tutorial Script Code)";
            }
        }
    }
}

